﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;

public partial class mainframe : System.Web.UI.Page
{
    SqlConnection conn;
    SqlCommand comm;
    SqlDataReader sdr;
    private Int64 userID = 0;
    public StringBuilder BusinessModule = new StringBuilder();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userID"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            conn = DBTools.getDBConnection();
            comm = new SqlCommand("", conn);
            userID = Int64.Parse(Session["userID"].ToString());
            StringBuilder sql = new StringBuilder();
            sql.Append(" select"                                                                + Environment.NewLine);
            sql.Append(" A4.ID,"                                                                + Environment.NewLine);
            sql.Append(" A4.Name"                                                               + Environment.NewLine);
            sql.Append(" from"                                                                  + Environment.NewLine);
            sql.Append(" SH_YXK_User as A"                                                      + Environment.NewLine);
            sql.Append(" join SH_YXK_UserFunctionRelation as A1 on A1.Users = A.ID"             + Environment.NewLine);
            sql.Append(" join SH_YXK_BusinessFunction as A2 on A2.ID = A1.BusinessFunction"     + Environment.NewLine);
            sql.Append(" join SH_YXK_BusinessClass as A3 on A3.ID = A2.BusinessClass"           + Environment.NewLine);
            sql.Append(" join SH_YXK_BusinessModule as A4 on A4.ID = A3.BusinessModule"         + Environment.NewLine);
            sql.Append(" where A.ID = "+userID+" "                                              + Environment.NewLine);
            sql.Append(" group by"                                                              + Environment.NewLine);
            sql.Append(" A4.ID,"                                                                + Environment.NewLine);
            sql.Append(" A4.Name"                                                               + Environment.NewLine);
            comm.CommandText = sql.ToString();
            conn.Open();
            sdr = comm.ExecuteReader();
            BusinessModule.Append("<ul>" + Environment.NewLine);
            int i = 1;
            while (sdr.Read())
            {
                if(i == 1)
                    BusinessModule.Append("<li id=\"man_nav_" + i + "\" onclick=\"list_sub_nav(id," + sdr["ID"] + ")\"  class=\"bg_image_onclick\">" + sdr["Name"] + "</li>" + Environment.NewLine);
                else
                    BusinessModule.Append("<li id=\"man_nav_" + i + "\" onclick=\"list_sub_nav(id," + sdr["ID"] + ")\"  class=\"bg_image\">" + sdr["Name"] + "</li>" + Environment.NewLine);
                i = i + 1;
            }
            sdr.Close();
            conn.Close();
            BusinessModule.Append("</ul>" + Environment.NewLine);
        }
    }
}